//******************************************************************/
//版本说明:
//V0.1		2017-03-30	11:00	yshao	复制自SL909_G01_X32
//******************************************************************/
`timescale	1ps/1ps
module SL909_N03(
                input	wire		sclkin,
                input   wire		key_in,
                
                output  wire            JP202_PIN3,
                output  wire            JP202_PIN4,
		output	wire		JP202_PIN5,
                input	wire            JP202_PIN6,

		output	wire		sa_clk,
		output	wire	[2:0]	sa_cnt,
		output	wire		sa_dqm_l,
		output	wire		sa_dqm_h,
		output	wire	[10:0]	sa_addr,
                output	wire	[1:0]	sa_bank,
		inout	tri	[31:0]	sa_data,

		input	wire		mcu_dmx_tx,		//uart2_sync,
		output	wire		mcu_dmx_rx,		//uart3_sync,	

		input	wire		mcu_fpga_ctrl,		//mcu到fpga的模式控制信号

		input	wire		mcu_spi_fpga,		//spi工作在通讯模式		
		input	wire		mcu_spi_clk,
		input	wire		mcu_spi_mosi,
		output	reg		mcu_spi_miso,
		output	wire		spi2_cs,
		output	wire		spi2_clk,
		output	wire		spi2_mosi,
								
		output	wire		sd_clk,
		inout	tri		sd_cmd_sdi,
		input	wire		sd_dat0_sdo,
		input	wire		sd_dat1,
		input	wire		sd_dat2,
		inout	wire		sd_dat3_cs,
		input	wire		sd_cd,
		input	wire		sd_wp,

		input	wire		gp0_rxc,
		input	wire		gp0_rxdv,
		input	wire	[3:0]	gp0_rxd,
		output	wire		gp0_txc,
		output	wire		gp0_txen,
		output	wire	[3:0]	gp0_txd,
		
		input	wire		gp1_rxc,
		input	wire		gp1_rxdv,
		input	wire	[3:0]	gp1_rxd,
		output	wire		gp1_txc,
		output	wire		gp1_txen,
		output	wire	[3:0]	gp1_txd,

		output	wire	[7:0]	port_da,
		output	wire	[7:0]	port_le,
		input	wire	[7:0]	port_ex,
		
		input	wire	[7:0]	port_in,
		
		output	wire		led_g
		);

//****************************************************************
//		内部信号
//****************************************************************
wire		resetb,oclk,clk_150M,sclk;
wire		time_1us,time_1ms,time_125ms,time_250ms,time_1s;
wire		time_1ms_sync,time_16us_sync,time_15ms_sync,time_250ms_sync,time_1s_sync;

wire		oclk_err,key_press;

wire		init_end,init_mode,comm_en;

wire		local_depth_en,cas_depth_adj;
wire	[7:0]   local_depth;

wire		rec_flag,rec_error,send_flag,pre_flag;
wire	[7:0]	rec_data,send_data;
wire	[1:0]	rec_vendor;
wire		yt_vs_pre,input_active,redu_flag,blank_flag;
wire	[7:0]	phy_state;
//A口接收到的信号
wire		rec_flag_a, rec_error_a, send_flag_a, pre_flag_a;
wire	[7:0]	rec_data_a, send_data_a;                

//PHY设置总线相关信号
wire		set_d_ok, ext_d_ok;
wire	[15:0]	set_addr, ext_addr;
wire	[7:0]	set_data;

//MCU设置总线相关信号
wire		mcu_set_d_ok, mcu_ext_d_ok;
wire	[15:0]	mcu_set_addr, mcu_ext_addr;
wire	[7:0]	mcu_set_data;

//MUC接口相关
wire		mcu_com_miso, mcu_sd_miso, mcu_flash_miso;

//显示数据相关
reg		vs,ds,h_start;
reg	[7:0]	data;
reg	[10:0]	h_num;
wire    [10:0]  h_total,l_total;
wire		vs_a,ds_a,v_start_a,h_start_a;
wire	[7:0]	data_a,state,state_2;
wire	[10:0]	h_num_a;
wire	[63:0]	unit_color_adj;

wire		black,black_mark;

//**********配置参数**************
wire	[1:0]	color_restore_type;
wire	[7:0]	led_light;
wire	[7:0]	testmode;
wire	[7:0]	no_vs_set;

//**********mcu-fpga**************
wire		op_addr_mask;

wire		spi_rec_flag;
wire	[7:0]	spi_rec_data;
wire		spi_rec_error;
wire	[1:0]	spi_rec_vendor;

wire		spi_send_flag;
wire		spi_send_pre;
wire	[7:0]	spi_send_data;

wire		mcu_dmx_en, mcu_dmx_ten;
wire	[7:0]	port_sel, dmx_ack_in;
wire		mcu_flash_en, mcu_sd_en, mcu_sd_rd, sd_valid;
wire	[7:0]	fpga_state;

//**********显示和输出**************
wire		vs_out;
reg		vs_b;
wire		ds_b, h_start_b;
wire	[7:0]	data_b;
wire	[2:0]	h_num_b;
wire		artnet_flag;
reg		artnet_mode;
wire	[7:0]	l9_com_tout;

wire		disp_read_req;
wire	[23:0]	disp_read_addr;
wire	[3:0]	disp_read_cnt;
wire            disp_read_ack;
wire    [31:0]  disp_read_data;

reg	[5:0]	time_33ms_count;

wire 	[7:0]	out_data;
wire 	[7:0]	out_data_n;
wire            clk_out;
wire            clk_out_n;

//DMX输出信号
wire	[1:0]	dmx_mode;
wire	[2:0]	waddr_mode;
wire		dmx_rec_en,pin4_w_active;
wire	[7:0]	out_data_dmx, waddr_data;

wire		nomal_driver,dect_in,dect_out;

//**********调试用信号**********
wire	[7:0]	disp_tout,spi_tout;
wire	[31:0]	out_tout,dect_tout,ack_tout,sa_tout;

//******************************************************************/
//			   参数定义
//******************************************************************/
//常数定义
parameter	SUB	=0;	   //分控
parameter	ASSIST	=1;	   //附属设备

parameter	ACTIVE	=1;
parameter	TEST	=2;
parameter	INIT	=3;

parameter	INIT_ADDR	=14'b0000_0000_1100_00;//0x00C0_0000~0x00C3_FFFF
parameter	TEST_ADDR	=14'b0000_0000_1100_01;//0x00C4_0000~0x00C7_FFFF
parameter	ACT_ADDR	=14'b0000_0000_1100_10;//0x00C8_0000~0x00CB_FFFF

//仿真模式
parameter	Sim_Mode	=0;
parameter	LOGIC_MODE	=ACTIVE;

//程序版本信息
parameter	MAIN_FUNCTION	=  "S";		//ASCII "S"  
parameter	SUB_FUNCTION	=  "L";		//ASCII "L"  
parameter	MAIN_FSOLUTION	=  9;		//"9"        
parameter	SUB_SOLUTION	=  9;		//"09"       
parameter	APPLICATION_TYPE=  "G";		//ASCII "G"  
parameter	MAIN_VERSION	=  8'd3;	//"03"       
parameter	SUB_VERSION	=  8'd7;	//"X01"  
parameter	MINI_VERSION	=  8'd5;	//" "  


//模块参数设置
defparam	sys_reset_clk.Sim_Mode 	= Sim_Mode;
defparam	out_ctrl_lamp.Sim_Mode 	= Sim_Mode;
defparam	sdram_top.Sim_Mode	= Sim_Mode;

defparam	phy_interface.DEVICE_TYPE		=SUB;

defparam	phy_comm.com_ctrl.DEVICE_TYPE		=SUB; 
defparam	phy_comm.com_ctrl.INITIAL_ADDR		=INIT_ADDR;
defparam	phy_comm.com_ctrl.TEST_ADDR		=TEST_ADDR;
defparam	phy_comm.com_ctrl.ACTIVE_ADDR		=ACT_ADDR;

defparam	phy_comm.state_ctrl.main_function	=MAIN_FUNCTION;
defparam	phy_comm.state_ctrl.sub_function	=SUB_FUNCTION;
defparam	phy_comm.state_ctrl.main_solution	=MAIN_FSOLUTION;
defparam	phy_comm.state_ctrl.sub_solution	=SUB_SOLUTION;
defparam	phy_comm.state_ctrl.application_type	=APPLICATION_TYPE;
defparam	phy_comm.state_ctrl.main_version	=MAIN_VERSION;
defparam	phy_comm.state_ctrl.sub_version		=SUB_VERSION;
defparam	phy_comm.state_ctrl.mini_version	=MINI_VERSION;

defparam	sys_mode_ctrl.reboot_ctrl.LOGIC_MODE	=LOGIC_MODE;

defparam        mcu_comm.main_function   =	MAIN_FUNCTION;
defparam        mcu_comm.sub_function    =	SUB_FUNCTION;
defparam        mcu_comm.main_solution   =	MAIN_FSOLUTION;
defparam        mcu_comm.sub_solution    =	SUB_SOLUTION;
defparam        mcu_comm.application_type=	APPLICATION_TYPE;
defparam        mcu_comm.main_version    =	MAIN_VERSION;
defparam        mcu_comm.sub_version     =	SUB_VERSION;
defparam        mcu_comm.mini_version     =	MINI_VERSION;
defparam        mcu_comm.LOGIC_MODE     =	LOGIC_MODE;

//**************************************************************
//			整体控制
//**************************************************************
//********时钟复位管理单元********
sys_reset_clk sys_reset_clk(
		.sclkin(sclkin),
        
		.resetb(resetb),
		.sclk(sclk),
		.oclk(oclk),
		.sa_clk(sa_clk),
		.clk_25M(clk_25M),
        
		.key_input(key_press),
		.oclk_err(oclk_err),
        
		.time_1us(time_1us),
		.time_1ms(time_1ms),
		.time_125ms(time_125ms),
		.time_250ms(time_250ms),
		.time_1s(time_1s),
		
		.time_1ms_sync(time_1ms_sync),
		.time_16us_sync(time_16us_sync),
		.time_15ms_sync(time_15ms_sync),
		.time_125ms_sync(time_125ms_sync),
		.time_250ms_sync(time_250ms_sync),
		.time_1s_sync(time_1s_sync),
	
		.tout()   
		);
               
//********模式，复位，按键和指示********
sys_mode_ctrl sys_mode_ctrl(
		.resetb(resetb),
		.sclk(sclk),
        
		.time_1ms(time_1ms),
		.time_250ms(time_250ms),
		.time_250ms_sync(time_250ms_sync),

		//设置总线		
		.ext_d_ok(ext_d_ok),
		.ext_addr(ext_addr),
		.set_addr(set_data),
		.set_data(set_data),

		.mcu_ext_d_ok(mcu_ext_d_ok),
		.mcu_ext_addr(mcu_ext_addr),
		.mcu_set_addr(mcu_set_addr),
		.mcu_set_data(mcu_set_data),
	
		//按键输入检测
		.key_input(key_in),
		.press_detect(key_press),
		
		//工作模式
		.init_end(init_end),
		.init_mode(init_mode),
		.comm_en(comm_en),
		
		//指示灯相关
		.G_flash(rec_flag),
		.nG_led(led_g),
	
		.tout()   
		);

//**************************************************************
//		   千兆级联模块
//**************************************************************    
phy_interface phy_interface(
		.resetb(resetb),
		.sclk(sclk),
		.clk_25M(clk_25M),
                
		.cas_depth_adj(cas_depth_adj),
		.local_depth(local_depth),

		.tx_err_en(1'b0),
		.time_1ms(time_1ms),
		.time_125ms(time_125ms),	

		.gp0_rxc(gp0_rxc),
		.gp0_rxdv(gp0_rxdv),
		.gp0_rxd(gp0_rxd),
		.gp0_txc(gp0_txc),
		.gp0_txen(gp0_txen),
		.gp0_txd(gp0_txd),
		
		.gp1_rxc(gp1_rxc),
		.gp1_rxdv(gp1_rxdv),
		.gp1_rxd(gp1_rxd),
		.gp1_txc(gp1_txc),
		.gp1_txen(gp1_txen),
		.gp1_txd(gp1_txd),
		
		.rec_flag(rec_flag),
		.rec_data(rec_data),
		.rec_error(rec_error),
		.rec_error_sync(),
		
		.send_flag(send_flag),
		.pre_flag(pre_flag),
		.send_data(send_data),

		.rec_vendor(rec_vendor),
		.yt_vs_pre(yt_vs_pre),
		.input_active(input_active),
		.redu_flag(redu_flag),
		.blank_flag(blank_flag),
		.phy_state(phy_state),
		
		.rec_flag_a(rec_flag_a),
		.rec_data_a(rec_data_a),
		.rec_error_a(rec_error_a),

		.send_flag_a(send_flag_a),
		.pre_flag_a(pre_flag_a),
		.send_data_a(send_data_a),

		.tout()
		);

//**************************************************************
//		PHY通讯包解析
//**************************************************************        
//iColor通讯设置包解析
v8_phy_com_01 phy_comm(
		.resetb(resetb),
		.sclk(sclk),
		.time_1ms_sync(time_1ms_sync),
		
		//整体工作控制
		.comm_en(comm_en),
		.init_mode(init_mode),
		.init_end(init_end),

		//级联地址设定
		.local_depth_en(local_depth_en),
		.local_depth(local_depth),
		.current_depth(current_depth),

		//phy接口
		.rec_vendor(rec_vendor),
		.blank_flag(blank_flag),
		.redu_flag(redu_flag),
		.phy_state(phy_state),
		
		.rec_flag(rec_flag),
		.rec_error(rec_error),
		.rec_data(rec_data),
		
		.send_flag(send_flag),
		.pre_flag(pre_flag),
		.send_data(send_data),
		
		//内部寄存器设置总线
		.set_d_ok(set_d_ok),
		.set_addr(set_addr),
		.set_data(set_data),
		
		.ext_d_ok(ext_d_ok),
		.ext_addr(ext_addr),
		
		//逐点调整数据设置总线
		.init_correct_d_ok(),
		.init_correct_addr(),
		.init_correct_data(),
		.load_adj_flag(),
		.load_picture_flag(),
		
		//DMX模块返回的状态数据
		.dmx_ack_data(dmx_ack_data),
		.dmx_state_data(dmx_state_data),
		
		//调试用返回的状态数据
		.debug_data({cas_depth_adj,local_depth_en}),
		
		//输出给led灯和输出控制模块
		.black_mark(black_mark),

		//MCU直接操作Flash
		.mcu_flash_en(mcu_flash_en),
		
		.mcu_spi_cs(mcu_spi_fpga),
		.mcu_spi_clk(mcu_spi_clk),
		.mcu_spi_mosi(mcu_spi_mosi),
		.mcu_spi_miso(mcu_flash_miso),

		//调试信号接口
		.tout()
		);
		
//Artnet包iColor包ARP包转发MCU
//Artnet显示数据包提取
L9_com_ctrl_02 com_ctrl_b(
		.resetb(resetb),
		.sclk(sclk),
		.comm_en(comm_en),

		.current_depth(current_depth),
		.local_net(local_net),
       		.local_net_en(local_net_en),
		
		.rec_flag(rec_flag_a),
		.rec_data(rec_data_a),
		.rec_error(rec_error_a),
		
		.blank_flag(blank_flag),
		.redu_flag(redu_flag),
		.time_1ms_sync(time_1ms_sync),
		
		.op_addr_mask(op_addr_mask),

		.spi2_cs(spi2_cs),
		.spi2_clk(spi2_clk),
		.spi2_mosi(spi2_mosi),
		
		.artnet_flag(artnet_flag),
		.dsout(ds_b),
		.dout(data_b),
		.h_start(h_start_b),
		.h_num(h_num_b),
		.l2048_mode(),
		
		.tout(l9_com_tout)
		);

//iColor显示数据包提取
L9_data_rec_02 data_rec(
		.resetb(resetb),
		.sclk(sclk),
		
		//配置总线
		.set_d_ok(set_d_ok),
		.set_addr(set_addr),
		.set_data(set_data),
	        
		//工作模式控制
		.init_mode(init_mode),
		.black(black),
		
		//开机渐亮控制
		.test_vs(0),
		.local_test_en(0),
		.local_picture_en(0),        
		
		.local_net(local_net),
       		.local_net_en(local_net_en),

		//多模块共用设置数据输出
		.h_total(h_total),
		.l_total(l_total),
		.no_vs_set(no_vs_set),
		.local_depth(local_depth),
       		.cas_depth_adj(cas_depth_adj),
       		.local_depth_en(local_depth_en),
		
		//PHY模块接口
		.mac_flag(rec_flag),
		.mac_data(rec_data),
		.mac_error(rec_error),
		.mac_vendor(rec_vendor),
		
		//显示数据输出
		.vsout(vs_a),
		.dsout(ds_a),
		.dout(data_a),
		.h_start(h_start_a),
		.h_num(h_num_a),
		.l2048_mode(l2048_mode),
		
                //显示设置数据输出
		.state(state),	
		.state_2(state_2),
		.color_restore_type(color_restore_type),
		.testmode(testmode),
		.unit_color_adj(unit_color_adj),
		.cascade_light(),
		.led_light(led_light),

		//调试用信号输出
		.tout()
		);
		
//**************************************************************
//		  MCU控制接口
//************************************************************** 
//MCU到FPGA的SPI接口
L9_spi_com_01 mcu_comm(
		.resetb(resetb),
		.sclk(sclk),
		.comm_en(comm_en),
		
		//MCU到FPGA接口	
		.mcu_spi_cs(mcu_spi_fpga),
		.mcu_spi_clk(mcu_spi_clk),
		.mcu_spi_mosi(mcu_spi_mosi),
		.mcu_spi_miso(mcu_com_miso),

		.mcu_fpga_ctrl(mcu_fpga_ctrl),
		
		//返回PHY数据包	
		.send_flag(send_flag_a),
		.pre_flag(pre_flag_a),
		.send_data(send_data_a),
		
	        //MCU控制总线
		.mcu_set_en(),
		
		.mcu_set_d_ok(mcu_set_d_ok),
		.mcu_set_addr(mcu_set_addr),
		.mcu_set_data(mcu_set_data),
		
		.mcu_ext_d_ok(mcu_ext_d_ok),
		.mcu_ext_addr(mcu_ext_addr),
		
		.fpga_state(fpga_state),

		//和输出模块接口	
		.mcu_dmx_en(mcu_dmx_en),
		.port_sel(port_sel),
		.mcu_dmx_ten(mcu_dmx_ten),
		
		//SD卡接口信号
		.mcu_sd_en(mcu_sd_en),
		.mcu_sd_rd(mcu_sd_rd),
		
		//和Flash接口	
		.mcu_flash_en(mcu_flash_en),

		//调试信号
		.tout(spi_tout)
		);

//assign	mcu_flash_en = 0;
assign	fpga_state = {mcu_dmx_en, mcu_flash_en, mcu_sd_en, comm_en, sd_valid};

always @( * )
	if (mcu_sd_en == 1)
		mcu_spi_miso <= mcu_sd_miso;
	else if (mcu_flash_en == 1)
		mcu_spi_miso <= mcu_flash_miso;
	else if (mcu_spi_fpga == 0)
		mcu_spi_miso <= mcu_com_miso;
	else
		mcu_spi_miso <= 0;
		
//************************************************************/
//		SD卡控制
//************************************************************/
wire		sd_mcu_clk, sd_mcu_cmd_oe, sd_mcu_cmd_out;
reg		sd_clk_out, sd_cmd_oe, sd_cmd_out;
wire	[3:0]	sd_dat_in;

//SD卡插入检测
sd_cd_dect sd_cd_dect(
		.resetb(resetb),
		.sclk(sclk),
		
		.t_ms_sync(time_1ms_sync),
               
		.sd_cd(sd_cd),
		
		.sd_valid(sd_valid),
		
		.tout()
		);

//mcu通过FPGA直接控制SD卡
mcu_sd_cnt mcu_sd_cnt(
		.resetb(resetb),
		.sclk(sclk),
                
		.mcu_sd_en(mcu_sd_en),
		.mcu_sd_rd(mcu_sd_rd),
		
		.mcu_spi_clk(mcu_spi_clk),
		.mcu_spi_mosi(mcu_spi_mosi),
		.mcu_spi_miso(mcu_sd_miso),
                
		.sd_clk(sd_mcu_clk),
		.sd_cmd_oe(sd_mcu_cmd_oe),
		.sd_cmd_out(sd_mcu_cmd_out),
		.sd_cmd_in(sd_cmd_in),
		.sd_dat_oe(),
		.sd_dat_out(),
		.sd_dat_in(sd_dat_in),
		
		.tout()
		);
		
//always	@( * )
//	sd_dat_dis <= sd_dat_mcu;

always	@( * )
//	if (f_work == 1) begin
//		sd_clk_out <= sd_play_clk;
//		sd_cmd_oe <= sd_play_cmd_oe;
//		sd_cmd_out <= sd_play_cmd_out;
//		end
//	else begin
	begin
		sd_clk_out <= sd_mcu_clk;
		sd_cmd_oe <= sd_mcu_cmd_oe;
		sd_cmd_out <= sd_mcu_cmd_out;
		end

//SD卡输出控制
assign	sd_clk = sd_clk_out;
assign	sd_cmd_sdi = (sd_cmd_oe == 1)?sd_cmd_out:1'bz;

//SD卡输入控制
assign	sd_cmd_in = sd_cmd_sdi;
assign	sd_dat_in = {sd_dat3_cs, sd_dat2, sd_dat1, sd_dat0_sdo};

//**************************************************************
//         显示数据存储与读取
//************************************************************** 
always @(posedge sclk or negedge resetb)
	if (resetb == 0)
		artnet_mode <= 0;
	else if (artnet_flag == 1)
		artnet_mode <= 1;
	else if (vs_a == 1)
		artnet_mode <= 0;

always @(posedge sclk or negedge resetb)
	if (resetb == 0)
		time_33ms_count <= 0;
	else if (time_33ms_count[5] == 1)
		time_33ms_count <= 0;
	else if (time_1ms_sync == 1)
		time_33ms_count <= time_33ms_count + 1;

always @(posedge sclk)
	if (artnet_mode == 1 && time_33ms_count == 1 && time_1ms_sync == 1)
		vs_b <= 1;
	else
		vs_b <= 0;

always @(posedge sclk)
	vs <= vs_a | vs_b;
	
always @(posedge sclk)
	if (artnet_mode == 1) begin
		ds <= ds_b;
		h_num <= h_num_b;
		data <= data_b;
		h_start <= h_start_b;
	end
	else begin
		ds <= ds_a;
		h_num <= h_num_a;
		data <= data_a;
		h_start <= h_start_a;
	end

s8_sdram_top_01 sdram_top(
		.resetb(resetb),
		.sclk(sclk),

		.init_mode(init_mode),
		.set_addr(set_addr),	
		.set_data(set_data),
		.set_d_ok(set_d_ok),
	
		.sync_16_us(time_16us_sync),
        
		.vsin(vs),
		.dsin(ds),
		.din(data),
		.h_start(h_start),
		.h_num(h_num),
		.l2048_mode(l2048_mode),
		.artnet_mode(artnet_mode),
        
		.vs_out(vs_out),
		.state(state),

		.read_req (disp_read_req),
		.read_addr(disp_read_addr),
		.read_cnt(disp_read_cnt),
		.read_ack (disp_read_ack),
		.read_data(disp_read_data),

		.sa_clk(),
		.sa_cnt(sa_cnt),
		.sa_addr(sa_addr),
		.sa_bank(sa_bank),
		.sa_data(sa_data),
        
		.tout(sa_tout)
        	);

assign        sa_dqm_l=0;
assign        sa_dqm_h=0;

//**************************************************************
//		        输出控制
//************************************************************** 
//in    input_active,no_vs_set,comm_en
//in    set_d_ok,set_addr,set_data
//

//out   显示输出接口

//黑屏控制
black_ctrl      black_ctrl(
		.resetb(resetb),
		.sclk(sclk),
                
		.time_125ms_sync(time_125ms_sync),
		.init_mode(init_mode),
		.input_active(0),
		.local_test_en(0),
                
		.black_mark(black_mark),                  
		.state(state), 
		.no_vs_set(no_vs_set),
                
		.black(black)
                );  

//灯饰输出控制模块
out_ctrl_lamp out_ctrl_lamp(
		.resetb			(resetb),
		.sclk			(sclk),
		.oclk			(oclk),
        
		.set_d_ok		(set_d_ok),
		.set_addr		(set_addr),
		.set_data		(set_data),
        
		.ext_d_ok		(ext_d_ok),
		.ext_addr		(ext_addr),

		.init_correct_d_ok	(0),
		.init_correct_addr	(0),
		.init_correct_data	(0),
        
		.t_us			(time_1us),
		.t_ms			(time_1ms),
		.t_s			(time_1s),

		.out_en			(comm_en),
		.v_start		(vs),
		.black			(black),
		.state			(state),
		.state_2		(state_2),
		.color_restore_type	(color_restore_type),
		.led_light		(led_light),
        
		.unit_color_adj		(unit_color_adj),

		.disp_read_req		(disp_read_req),
		.disp_read_addr		(disp_read_addr),
		.disp_read_cnt		(disp_read_cnt),
		.disp_read_ack		(disp_read_ack),
		.disp_read_data		(disp_read_data),
               
		.vs_out			(vs_out),
        
		.out_sync		(out_sync),
		.out_data		(out_data),
		.out_data_n		(out_data_n),
		.clk_out		(clk_out),
		.clk_out_n		(clk_out_n),

		//DMX输出信号
		.dmx_mode		(dmx_mode),
		.dmx_rec_en		(dmx_rec_en),
		.out_data_dmx		(out_data_dmx),
		//DMX写址信号
		.pin4_w_active		(pin4_w_active),
		.waddr_mode		(waddr_mode),
		.waddr_data		(waddr_data),

		.mem_err_sel		(),
		.err_port_num		(),
		.err_read_start		(),
		.div_count_max		(),
		.mem_active_port	(),
		.mem_read_start		(),

		.tout			(out_tout)     
		);

//************************************************************/
//		背板接口
//************************************************************/
wire	[7:0]	port_da_d, port_le_d, port_ex_d;

assign  port_da = port_da_d;  
assign  port_le = port_le_d;  
//assign	port_ex[3:0] = (dmx_mode[1]==1)?{4'hz}:port_ex_d[3:0];
//assign	port_ex[4]   = 1'hz;
//assign	port_ex[7:5] = (dmx_mode[1]==1)?{3'hz}:port_ex_d[7:5];
//assign	port_ex[7:5] = {1'hz,dect_out,1'hz};

//返回dmx接收数据
assign	dmx_ack_in = port_ex[7:0];
assign	dect_in = port_ex[4];

wire	dect_ttt;
assign	dect_ttt = port_ex[7];

//背板类型检测
/*
hub_detect hub_detect(
	.resetb(resetb),
	.sclk(sclk),

	.dect_out(dect_out),	
	.dect_in(dect_in),
		
	.nomal_driver(nomal_driver),	

	.tout(dect_tout)	
	);
		
*/
assign nomal_driver = 1;

port_map port_map(
		.resetb			(resetb),
		.sclk			(sclk),
        	
		.dect_out		(0),
		.nomal_driver		(nomal_driver),

		.testmode		(testmode),
		.dmx_mode		(dmx_mode),
		.waddr_mode		(waddr_mode),
        
		.port_sel		(port_sel),
		.mcu_dmx_en		(mcu_dmx_en),
		.mcu_dmx_ten		(mcu_dmx_ten),
		.mcu_dmx_tx		(mcu_dmx_tx),
		.mcu_dmx_rx		(mcu_dmx_rx),
        
		.out_data		(out_data),
		.out_data_n		(out_data_n),
		.clk_out		(clk_out),
		.clk_out_n		(clk_out_n),
		
		.out_data_dmx		(out_data_dmx),
		.dmx_rec_en		(dmx_rec_en),
		
		.pin4_w_active		(pin4_w_active),
		.waddr_data		(waddr_data),
        
		.port_da_d		(port_da_d),
		.port_le_d		(port_le_d),
		.port_ex_d		(port_ex_d),
		.dmx_ack_in		(dmx_ack_in),
        
		.tout			(out_tout)   
		);

//************************************************************/
//		未用接口
//************************************************************/                    
//assign  port_le = {sd_clk,sd_cmd_sdi,sd_dat0_sdo,sd_dat1,sd_dat2,sd_dat3_cs,sd_cd,sd_wp};  
//assign  port_da = {mcu_spi_fpga,mcu_spi_clk,mcu_spi_mosi,mcu_spi_miso,mcu_fpga_ctrl,mcu_sd_en,mcu_sd_rd,1'b0};  
//assign  port_le = {mcu_spi_fpga, mcu_spi_clk, mcu_spi_mosi, mcu_spi_miso, mcu_fpga_ctrl, mcu_sd_en, mcu_sd_rd};  
//assign  port_da = spi_tout;

//assign	JP202_PIN3 = mcu_spi_fpga;
//assign	JP202_PIN4 = mcu_spi_clk;
//assign	JP202_PIN5 = mcu_spi_mosi;
assign	JP202_PIN3 = spi2_cs & mcu_spi_fpga;
assign	JP202_PIN4 = spi2_clk | mcu_spi_clk;
assign	JP202_PIN5 = spi2_mosi | mcu_spi_mosi;

endmodule


